package com.qf.api.sys.dto;

import cn.hutool.core.bean.BeanUtil;
import com.qf.api.sys.entity.SysOperationLogEntity;
import com.qf.core.annotation.ExcelColumn;
import com.qf.core.annotation.ExcelSheet;
import com.qf.core.enums.BasicEnumUtil;
import com.qf.core.enums.common.BusinessTypeEnum;
import com.qf.core.enums.common.OperatorTypeEnum;
import com.qf.core.enums.common.RequestMethodEnum;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @Author: sin
 * @Date: 2025/5/12 9:55
 * @Description:
 **/
@Data
@ExcelSheet(name = "操作日志")
public class OperationLogDTO {
    public OperationLogDTO(SysOperationLogEntity entity) {
        if (entity != null) {
            BeanUtil.copyProperties(entity, this);
            this.requestMethod = BasicEnumUtil.getDescriptionByValue(RequestMethodEnum.class,
                entity.getRequestMethod());
            businessTypeStr = BasicEnumUtil.getDescriptionByValue(BusinessTypeEnum.class, entity.getBusinessType());
            operatorTypeStr = BasicEnumUtil.getDescriptionByValue(OperatorTypeEnum.class, entity.getOperatorType());
            businessTypeCssTag = BasicEnumUtil.getCssTagByValue(BusinessTypeEnum.class, entity.getBusinessType());
            this.errorStack = StringUtils.isBlank(this.errorStack) ? "暂无": this.errorStack;
        }
    }
    @ExcelColumn(name = "ID",order = 0)
    private Long id;

    private Integer businessType;

    @ExcelColumn(name = "操作类型",order = 1)
    private String businessTypeStr;

    private String businessTypeCssTag;

    @ExcelColumn(name = "请求方式", order = 2)
    private String requestMethod;

    @ExcelColumn(name = "请求模块", order = 3)
    private String requestModule;

    @ExcelColumn(name = "请求详情", order = 4)
    private String requestDesc;

    @ExcelColumn(name = "请求链接", order = 5)
    private String requestUrl;

    @ExcelColumn(name = "调用方法", order = 6)
    private String calledMethod;

    private Integer operatorType;

    @ExcelColumn(name = "操作类型", order = 7)
    private String operatorTypeStr;

    @ExcelColumn(name = "用户ID", order = 8)
    private Long userId;

    @ExcelColumn(name = "用户名", order = 9)
    private String username;

    @ExcelColumn(name = "ip地址", order = 10)
    private String operatorIp;

    @ExcelColumn(name = "ip地点", order = 11)
    private String operatorLocation;

    @ExcelColumn(name = "请求参数", order = 12)
    private String operationParam;

    @ExcelColumn(name = "响应结果", order = 13)
    private String operationResult;

    @ExcelColumn(name = "响应状态", order = 14)
    private Integer status;

    @ExcelColumn(name = "错误详情", order = 15)
    private String errorStack;

    @ExcelColumn(name = "操作时间", order = 16)
    private Date operationTime;
}
